#include "http.h"
#include "info.h"

int http_bind(void) {
/*
	int rlen=1,clen;

	httpsock.fd = socket(AF_INET, SOCK_STREAM, 0);
	if( httpsock.fd == -1) {
		printf("\n******************************\nImpossivel criar socket\n************************************\n");
		return -1;
	}

	if(setsockopt(httpsock.fd,SOL_SOCKET,SO_REUSEADDR,&rlen,sizeof(int)) == -1) {
		printf("\n******************************\nImpossivel definir opcoes para o socket\n**********************************\n");
		return -1;
	}

	httpsock.s.sin_family=AF_INET;
	httpsock.s.sin_port=htons(info.httpbind);
	httpsock.s.sin_addr.s_addr=INADDR_ANY;

	if( bind(httpsock.fd, (struct sockaddr *)&httpsock.s, sizeof(struct sockaddr_in)) == -1) {
		printf("\n******\nNao foi possive bindar porta\n*****");
	}

	listen(httpsock.fd,1);

	clen=sizeof(struct sockaddr_in);
	httpsock.fd2=accept(httpsock.fd,(struct sockaddr *)&httpsock.c, &clen);
	if(httpsock.fd2==-1) {
		printf("erro\n");
	}
	printf("fr\n");
	
*/
}

void *http(void *arg) {
	printf("aaaaaa\n");
	http_bind();
	printf("bbbbbbb\n");
	while(1) {
		sleep(2);
		printf("aa\n");

	}

	pthread_exit(0);

}
void http_start() {
/*
	pthread_attr_t tattr;
        pthread_t tid;
	int ret;
	void *arg;
	
	if(info.httpbind == 0) return;

	pthread_attr_init(&tattr);
	pthread_create(&tid, &tattr, http, arg);
*/
}

